﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using DLV.Utilities;
using DLV.Library.Utilities;

namespace DLV.Data.Entities
{
    public class PartnerController
    {
        public int InsertPartner(PartnerInfo info)
        {
            return SQL.InsertPartner(info.Logo, info.PartnerName, info.PartnerSortName, info.PartnerEnglishName, info.Phone, info.Telephone, info.Hotline, info.Fax, info.Email, info.Represent, info.Regency, info.ContinentId, info.NationalId, info.CityId, info.DistrictId, info.WardId, info.Address, info.CreatedBy, info.CreatedDate, info.UpdatedBy, info.UpdatedDate, info.Status);
        }
        public void UpdatePartner(PartnerInfo info)
        {
            SQL.UpdatePartner(info.PartnerId, info.Logo, info.PartnerName, info.PartnerSortName, info.PartnerEnglishName, info.Phone, info.Telephone, info.Hotline, info.Fax, info.Email, info.Represent, info.Regency, info.ContinentId, info.NationalId, info.CityId, info.DistrictId, info.WardId, info.Address, info.CreatedBy, info.CreatedDate, info.UpdatedBy, info.UpdatedDate, info.Status);
        }
        public void DeletePartner(PartnerInfo info)
        {
            DeletePartner(info.PartnerId);
        }
        public void DeletePartner(int partnerId)
        {
            SQL.DeletePartner(partnerId);
        }
        public PartnerInfo GetPartner(int partnerId)
        {
            return CBO.FillObject<PartnerInfo>(SQL.GetPartner(partnerId));
        }
        public List<PartnerInfo> ListPartner()
        {
            return CBO.FillCollection<PartnerInfo>(SQL.ListPartner());
        }

        public List<PartnerInfo> ListPartnerByStatus(int status)
        {
            return ListPartner().Where(p => p.Status == status).ToList();
        }
        public DataTable SelectPartner()
        {
            return CBO.ConvertToDataTable(ListPartner(), typeof(PartnerInfo));
        }
        public List<PartnerInfo> ListInsurancePartner()
        {
            return CBO.FillCollection<PartnerInfo>(SQL.ListInsurancePartner());
        }
        public Dictionary<object, object> ListPartnerLookup()
        {
            var pages = ListPartnerByStatus((int)Globals.DocumentStatus.Use).OrderBy(p => p.PartnerName);
            var dicpages = new Dictionary<object, object>();
            foreach (var info in pages)
                dicpages.Add(info.PartnerId, info.PartnerName);
            return dicpages;
        }
    }
}
